﻿namespace Sidvall.IdentityManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AspNetUserLogins : global::Sidvall.IdentityManager.UI.Entities.Core.BusinessBase, global::Sidvall.IdentityManager.Data.IAspNetUserLogins
    {
        #region Business Members

        #region LoginProvider

        private string _LoginProvider = string.Empty;
        partial void OnBeforeLoginProviderPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeLoginProviderPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterLoginProviderPropertyChanged();
        public string LoginProvider
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_LoginProvider);
                OnBeforeLoginProviderPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _LoginProvider);
                OnBeforeLoginProviderPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("LoginProvider", eventData.Value, true, true, true);
                    OnAfterLoginProviderPropertyChanged();
                }
            }
        }

        #endregion
        #region ProviderKey

        private string _ProviderKey = string.Empty;
        partial void OnBeforeProviderKeyPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeProviderKeyPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterProviderKeyPropertyChanged();
        public string ProviderKey
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_ProviderKey);
                OnBeforeProviderKeyPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ProviderKey);
                OnBeforeProviderKeyPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ProviderKey", eventData.Value, true, true, true);
                    OnAfterProviderKeyPropertyChanged();
                }
            }
        }

        #endregion
        #region UserId

        private string _UserId = string.Empty;
        partial void OnBeforeUserIdPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeUserIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserIdPropertyChanged();
        public string UserId
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_UserId);
                OnBeforeUserIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserId);
                OnBeforeUserIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("UserId", eventData.Value, true, true, true);
                    OnAfterUserIdPropertyChanged();
                }
            }
        }

        #endregion
        #region AspNetUser

        private AspNetUsers _AspNetUser;
        partial void OnBeforeAspNetUserPropertyChanged(Sidvall.Business.PropertyChangeEventData<AspNetUsers> eventData);
        partial void OnAfterAspNetUserPropertyChanged();
        public AspNetUsers AspNetUser
        {
            get
            {
                return _AspNetUser;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<AspNetUsers> eventData = new Sidvall.Business.PropertyChangeEventData<AspNetUsers>(value, _AspNetUser);
                OnBeforeAspNetUserPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("AspNetUser", eventData.Value, true, true, false);
                    OnAfterAspNetUserPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadAspNetUserAsync

        public async System.Threading.Tasks.Task<AspNetUsers> LoadAspNetUserAsync()
        {
            return await LoadAspNetUserAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<AspNetUsers> LoadAspNetUserAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetUsersField, global::Sidvall.IdentityManager.Data.Relations.AspNetUsersRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetUserLoginsManager.LoadAspNetUserAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.AspNetUser;
        }
        public AspNetUsers LoadAspNetUser(AspNetUsers item)
        {
            LoadInstanceField("AspNetUser", item, true, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public AspNetUserLogins Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public AspNetUserLogins Copy()
        {
            return Copy(null);
        }
        public AspNetUserLogins Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new AspNetUserLogins();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.IdentityManager.Data.IAspNetUserLogins item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.IdentityManager.Data.IAspNetUserLogins item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(AspNetUserLogins destination, global::Sidvall.IdentityManager.Data.IAspNetUserLogins source, Sidvall.Data.CopySettings copySettings);
        private void Import(AspNetUserLogins destination, global::Sidvall.IdentityManager.Data.IAspNetUserLogins source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(AspNetUserLogins destination, AspNetUserLogins source, Sidvall.Data.CopySettings copySettings);
        private void Import(AspNetUserLogins destination, AspNetUserLogins source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.IdentityManager.Data.IAspNetUserLogins, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AspNetUserLogins> SaveItemAsync()
        {
            return await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetUserLoginsManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<AspNetUserLogins> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetUserLoginsManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<AspNetUserLogins> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetUserLoginsManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<AspNetUserLogins> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetUserLoginsManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Initialize(this, settings);
        }

        #endregion
        
        #region IAspNetUserLogins Members

        string global::Sidvall.IdentityManager.Data.IAspNetUserLogins.LoginProvider
        {
            get
            {
                return this._LoginProvider;
            }
            set
            {
                this._LoginProvider = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IAspNetUserLogins.ProviderKey
        {
            get
            {
                return this._ProviderKey;
            }
            set
            {
                this._ProviderKey = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IAspNetUserLogins.UserId
        {
            get
            {
                return this._UserId;
            }
            set
            {
                this._UserId = value;
            }
        }
        global::Sidvall.IdentityManager.Data.IAspNetUsers global::Sidvall.IdentityManager.Data.IAspNetUserLogins.AspNetUser
        {
            get
            {
                return this._AspNetUser;
            }
            set
            {
                UpdateChildProperty(this._AspNetUser, value);
                this._AspNetUser = value as AspNetUsers;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public AspNetUserLogins()
        {
        }

        public AspNetUserLogins(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}